Skip to content

feat(prometheus): support tsdb.retention.percentage#791

Open
rjhenry wants to merge 4 commits into
prometheus-community:mainfrom
rjhenry:main
Open

feat(prometheus): support tsdb.retention.percentage#791
rjhenry wants to merge 4 commits into
prometheus-community:mainfrom
rjhenry:main

Conversation

@rjhenry

@rjhenry rjhenry commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Configure storage.tsdb.retention in the configuration file for versions of Prometheus 3.11.0 and greater, rather than deprecated command line flags. This allows for configuring percentage-based retention.
This closes #790.

@github-actions github-actions Bot added enhancement New feature or request roles/prometheus labels Apr 22, 2026
@github-actions

github-actions Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Docs Build 📝

Thank you for contributing!✨

The docs for this PR have been published here:
https://prometheus-community.github.io/ansible/pr/791

You can compare to the docs for the main branch here:
https://prometheus-community.github.io/ansible/branch/main

The docsite for this PR is also available for download as an artifact from this run:
https://github.com/prometheus-community/ansible/actions/runs/29082270152

File changes:

Click to see the diff comparison.

NOTE: only file modifications are shown here. New and deleted files are excluded.
See the file list and check the published docs to see those files.

diff --git a/home/runner/work/ansible/ansible/docsbuild/base/prometheus_role.html b/home/runner/work/ansible/ansible/docsbuild/head/prometheus_role.html
index 4f75a75..8f4baeb 100644
--- a/home/runner/work/ansible/ansible/docsbuild/base/prometheus_role.html
+++ b/home/runner/work/ansible/ansible/docsbuild/head/prometheus_role.html
@@ -376,6 +376,16 @@ To check whether it is installed, run <code class="code docutils literal notrans
 </div></td>
 </tr>
 <tr class="row-even"><td><div class="ansible-option-cell">
+<div class="ansibleOptionAnchor" id="parameter-main--prometheus_storage_retention_percentage"></div><p class="ansible-option-title" id="ansible-collections-prometheus-prometheus-prometheus-role-parameter-main-prometheus-storage-retention-percentage"><strong>prometheus_storage_retention_percentage</strong></p>
+<a class="ansibleOptionLink" href="#parameter-main--prometheus_storage_retention_percentage" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
+</div></td>
+<td><div class="ansible-option-cell"><p>Maximum percent of total disk space allowed for block storage</p>
+<p>Set to 0 to disable percentage-based retention</p>
+<p>Supported only on Prometheus &gt;= 3.11.0</p>
+<p class="ansible-option-line"><strong class="ansible-option-default-bold">Default:</strong> <code class="ansible-option-default docutils literal notranslate"><span class="pre">&quot;0&quot;</span></code></p>
+</div></td>
+</tr>
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-main--prometheus_storage_retention_size"></div><p class="ansible-option-title" id="ansible-collections-prometheus-prometheus-prometheus-role-parameter-main-prometheus-storage-retention-size"><strong>prometheus_storage_retention_size</strong></p>
 <a class="ansibleOptionLink" href="#parameter-main--prometheus_storage_retention_size" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
@@ -385,7 +395,7 @@ To check whether it is installed, run <code class="code docutils literal notrans
 <p class="ansible-option-line"><strong class="ansible-option-default-bold">Default:</strong> <code class="ansible-option-default docutils literal notranslate"><span class="pre">&quot;0&quot;</span></code></p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-main--prometheus_system_group"></div><p class="ansible-option-title" id="ansible-collections-prometheus-prometheus-prometheus-role-parameter-main-prometheus-system-group"><strong>prometheus_system_group</strong></p>
 <a class="ansibleOptionLink" href="#parameter-main--prometheus_system_group" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
@@ -393,7 +403,7 @@ To check whether it is installed, run <code class="code docutils literal notrans
 <p class="ansible-option-line"><strong class="ansible-option-default-bold">Default:</strong> <code class="ansible-option-default docutils literal notranslate"><span class="pre">&quot;prometheus&quot;</span></code></p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-main--prometheus_system_user"></div><p class="ansible-option-title" id="ansible-collections-prometheus-prometheus-prometheus-role-parameter-main-prometheus-system-user"><strong>prometheus_system_user</strong></p>
 <a class="ansibleOptionLink" href="#parameter-main--prometheus_system_user" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
@@ -401,14 +411,14 @@ To check whether it is installed, run <code class="code docutils literal notrans
 <p class="ansible-option-line"><strong class="ansible-option-default-bold">Default:</strong> <code class="ansible-option-default docutils literal notranslate"><span class="pre">&quot;prometheus&quot;</span></code></p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-main--prometheus_targets"></div><p class="ansible-option-title" id="ansible-collections-prometheus-prometheus-prometheus-role-parameter-main-prometheus-targets"><strong>prometheus_targets</strong></p>
 <a class="ansibleOptionLink" href="#parameter-main--prometheus_targets" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">dictionary</span></p>
 </div></td>
 <td><div class="ansible-option-cell"><p>Targets which will be scraped.</p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-main--prometheus_version"></div><p class="ansible-option-title" id="ansible-collections-prometheus-prometheus-prometheus-role-parameter-main-prometheus-version"><strong>prometheus_version</strong></p>
 <a class="ansibleOptionLink" href="#parameter-main--prometheus_version" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
@@ -417,21 +427,21 @@ To check whether it is installed, run <code class="code docutils literal notrans
 <p class="ansible-option-line"><strong class="ansible-option-default-bold">Default:</strong> <code class="ansible-option-default docutils literal notranslate"><span class="pre">&quot;3.13.0&quot;</span></code></p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-main--prometheus_web_config"></div><p class="ansible-option-title" id="ansible-collections-prometheus-prometheus-prometheus-role-parameter-main-prometheus-web-config"><strong>prometheus_web_config</strong></p>
 <a class="ansibleOptionLink" href="#parameter-main--prometheus_web_config" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">dictionary</span></p>
 </div></td>
 <td><div class="ansible-option-cell"><p>A Prometheus <a class="reference external" href="https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md">web config yaml</a> for configuring TLS and auth.</p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-main--prometheus_web_external_url"></div><p class="ansible-option-title" id="ansible-collections-prometheus-prometheus-prometheus-role-parameter-main-prometheus-web-external-url"><strong>prometheus_web_external_url</strong></p>
 <a class="ansibleOptionLink" href="#parameter-main--prometheus_web_external_url" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
 <td><div class="ansible-option-cell"><p>External address on which prometheus is available. Useful when behind reverse proxy. Ex. `http://example.org/prometheus`</p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-main--prometheus_web_listen_address"></div><p class="ansible-option-title" id="ansible-collections-prometheus-prometheus-prometheus-role-parameter-main-prometheus-web-listen-address"><strong>prometheus_web_listen_address</strong></p>
 <a class="ansibleOptionLink" href="#parameter-main--prometheus_web_listen_address" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Apr 22, 2026
@rjhenry

rjhenry commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

I can't see any molecule tests that test for handling of the prometheus.yml config file (other than creation), or mention either prometheus_storage_retention or prometheus_storage_retention_size. That said, I'm not the most familar with Molecule, so it's entirely possible I'm missing something otherwise obvious!
As I couldn't see any tests to mimic, there aren't any introduced tests for the changes in this PR. I'm happy to add some if required, but would appreciate a pointer or two in the right direction (ie: at existing tests I can extend).

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 2, 2026

@gardar gardar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see any molecule tests that test for handling of the prometheus.yml config file (other than creation), or mention either prometheus_storage_retention or prometheus_storage_retention_size. That said, I'm not the most familar with Molecule, so it's entirely possible I'm missing something otherwise obvious!
As I couldn't see any tests to mimic, there aren't any introduced tests for the changes in this PR. I'm happy to add some if required, but would appreciate a pointer or two in the right direction (ie: at existing tests I can extend).

It might be a good idea to add this to the alternative molecule scenario, actually we're already overwriting the storage retention defaults there, so you could just add the percentage option and bump the prometheus version.

Comment thread roles/prometheus/templates/prometheus.service.j2
Comment thread roles/prometheus/templates/prometheus.service.j2
rjhenry added 2 commits July 10, 2026 06:35
Signed-off-by: Rick Henry <rjh@rickhenry.uk>
This adds a variable to configure Prometheus' percentage-based
retention. This feature was added in 3.11.0.

Signed-off-by: Rick Henry <rjh@rickhenry.uk>
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 10, 2026
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 10, 2026
@rjhenry rjhenry marked this pull request as draft July 10, 2026 08:04
@rjhenry

rjhenry commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Updating the Prometheus version used in the alternative tests is failing following the removal of --alertmanager.timeout in Prometheus 3.0. I'll take a look and fix.

EDIT: After a bit of reading and some local testing, things look good. I've updated the PR with changes. Hopefully, the next run of GitHub Actions tests will succeed.

rjhenry added 2 commits July 10, 2026 09:44
The `--alertmanager.timeout` flag was deprecated in 2.25.0 and removed
in 3.0.0, hence the removal here.

Signed-off-by: Rick Henry <rjh@rickhenry.uk>
Signed-off-by: Rick Henry <rjh@rickhenry.uk>
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 10, 2026
@rjhenry rjhenry marked this pull request as ready for review July 10, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment